using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter04
{
	/// <summary>
	/// Example03: The Long Jump
	/// A long-jumper (Fig. 4.12) leaves the ground at an angle 
	/// of 20.0^{\circle} above the horizontal and at a speed of 11.0 m/s.
	/// (A) How far does he jump in the horizontal direction? 
	/// (Assume his motion is equivalent to that of a particle.)
	/// (B) What is the maximum height reached?
	/// </summary>
	public class Example03
	{
		public Example03()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Velocity v = new L.Velocity();
			v.X = 11.0*Math.Cos(20.0*Math.PI/180.0);
			v.Y = 11.0*Math.Sin(20.0*Math.PI/180.0);
            Science.Mathematics.Calculus.PolynomialFunction poly = new Science.Mathematics.Calculus.PolynomialFunction();
			poly.MaximumPower = 1;
			poly.Which = 0;
			poly.Coefficient = v.Y;
			poly.Which = 1;
			poly.Coefficient = -L.Constant.AccelerationOfGravity;
			poly.FindRoot();
			double time = poly.Root[0].Real;
			//(A)
			double distance = v.X*time*2.0;
			result+=Convert.ToString(distance);
			//(B)
			double height = v.Y*time-0.5*L.Constant.AccelerationOfGravity*time*time;
            result+="   "+Convert.ToString(height);
		}
	}
}
